<template>
<a-modal
      title="修改答辩结果"
      :visible="visible"
      @ok="handleSave"
      @cancel="handleClose"
      width="950px"
      centered
    >
    <a-form :form="form" :layout="'inline'">
            <a-row :gutter="48">
              <a-col :sm="{span:8}" :lg="{span:8}" :xl="{span:8}">
                <a-form-item label="学号">
                  <a-input disabled placeholder="请输入..." v-model="data.xh"/>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:8}" :lg="{span:8}" :xl="{span:8}">
                <a-form-item label="姓名">
                  <a-input disabled placeholder="请输入..." v-model="data.xm"/>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:8}" :lg="{span:8}" :xl="{span:8}">
                <a-form-item label="导师姓名">
                  <a-input disabled placeholder="请输入..." v-model="data.dsxm"/>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:24}" :lg="{span:24}" :xl="{span:24}">
                <a-form-item label="答辩会毕业表决结果" v-bind="formItemLayout" style="display: block;">
                  <a-form-item >同意 <a-input-number :min="0" v-decorator="[
                'bybjjgtyrs',
                {
                  rules: [{ required: true, message: '请输入同意人数!' }]
                }
              ]"/> 人, </a-form-item><a-form-item >反对 <a-input-number :min="0" v-decorator="[
                'bybjjgfdrs',
                {
                  rules: [{ required: true, message: '请输入反对人数!' }]
                }
              ]" /> 人;</a-form-item><a-form-item >弃权 <a-input-number :min="0" v-decorator="[
                'bybjjgqqrs',
                {
                  rules: [{ required: true, message: '请输入弃权人数!' }]
                }
              ]" /> 人</a-form-item>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:24}" :lg="{span:24}" :xl="{span:24}">
                <a-form-item label="答辩会学位表决结果" v-bind="formItemLayout" style="display: block;">
                <a-form-item >同意 <a-input-number :min="0" v-decorator="[
                'xwbjjgtyrs',
                {
                  rules: [{ required: true, message: '请输入同意人数!' }]
                }
              ]" @change="handleConclusion" /> 人, </a-form-item><a-form-item >反对 <a-input-number :min="0" v-decorator="[
                'xwbjjgfdrs',
                {
                  rules: [{ required: true, message: '请输入反对人数!' }]
                }
              ]" @change="handleConclusion" /> 人;</a-form-item><a-form-item >弃权 <a-input-number :min="0" v-decorator="[
                'xwbjjgqqrs',
                {
                  rules: [{ required: true, message: '请输入弃权人数!' }]
                }
              ]" @change="handleConclusion" /> 人</a-form-item>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:24}" :lg="{span:24}" :xl="{span:24}">
                <a-form-item label="答辩成绩" v-bind="formItemLayout1" style="display: block;">
                  <a-form-item >优秀 <a-input-number :min="0" v-decorator="[
                'dbcjbjwyrs',
                {
                  rules: [{ required: true, message: '请输入评优秀人数!' }]
                }
              ]"/> 人, </a-form-item><a-form-item >良好 <a-input-number :min="0" v-decorator="[
                'dbcjbjwlrs',
                {
                  rules: [{ required: true, message: '请输入评良好人数!' }]
                }
              ]" /> 人;</a-form-item><a-form-item >一般 <a-input-number :min="0" v-decorator="[
                'dbcjbjwybrs',
                {
                  rules: [{ required: true, message: '请输入评一般人数!' }]
                }
              ]" /> 人;</a-form-item><a-form-item >不合格 <a-input-number :min="0" v-decorator="[
                'dbcjbjwbhgrs',
                {
                  rules: [{ required: true, message: '请输入评不合格人数!' }]
                }
              ]" /> 人</a-form-item>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:24}" :lg="{span:24}" :xl="{span:24}" >
                <a-form-item label="推荐优秀论文结果" v-bind="formItemLayout" style="display: block;">
                  <a-form-item >是 <a-input-number :min="0" v-decorator="[
                'tjyxlwjgtyrs',
                {
                  rules: [{ required: true, message: '请输入同意人数!' }]
                }
              ]"/> 人, </a-form-item><a-form-item >否 <a-input-number :min="0" v-decorator="[
                'tjyxlwjgfdrs',
                {
                  rules: [{ required: true, message: '请输入反对人数!' }]
                }
              ]" /> 人;
              </a-form-item>
              <!-- <a-form-item >弃权 <a-input-number :min="0" v-decorator="[
                'tjyxlwjgqqrs',
                {
                  rules: [{ required: true, message: '请输入弃权人数!' }]
                }
              ]" /> 人
              </a-form-item> -->
                </a-form-item>
              </a-col>
              <a-col :sm="{span:24}" :lg="{span:24}" :xl="{span:24}">
                <a-form-item label="答辩会决议(限800字以内)" v-bind="formItemLayout" style="display: block;">
                  <a-textarea v-model="dbhjy" maxlength="800" rows="5" v-decorator="['dbhjy',
                    {
                      rules: [{ required: true, message: '请输入答辩会决议!' }],
                    }
                  ]" :isClear="false"/>
                  <!-- <a-textarea v-decorator="[
                'dbhjy',
                {
                  rules: [{ required: true, message: '请输入答辩会决议!' }]
                }
              ]"  placeholder="请输入..." /> -->
                  <a-textarea style="background: #fff;color: rgba(0,0,0,.65)" :autosize="false" disabled v-model="dbhjyjgnr"/>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
    </a-modal>
</template>

<script>
import wangEditor from '../entry/wangEditor'

const formItemLayout = {
  labelCol: { span: 5 },
  wrapperCol: { span: 17 }
}
const formItemLayout1 = {
  labelCol: { span: 5 },
  wrapperCol: { span: 19 }
}
export default {
  props: {
    visible: {
      default: false
    },
    data: {
      default: function(){
        return {}
      }
    }
  },
  components: { wangEditor },
  data() {
    return {
      formItemLayout,
      formItemLayout1,
      form:this.$form.createForm(this,{
        onValuesChange:this.handleConclusion
      }),
      postData: {
        dbcjbjwyrs:'',
        dbcjbjwlrs:'',
        dbcjbjwybrs:'',
        dbcjbjwbhgrs:'',
        tjyxlwjgtyrs:'',
        tjyxlwjgfdrs:'',
        // tjyxlwjgqqrs:'',
        xwbjjgtyrs:'',
        xwbjjgfdrs:'',
        xwbjjgqqrs:'',
        bybjjgfdrs:'',
        bybjjgqqrs:'',
        bybjjgtyrs:'',
        dbhjy:'',
      },
      dbhjyjgnr:'',
      dbhjy: ''
    }
  },
  watch:{
    data(val){
      this.handleLoad();
    }
  },
  mounted () {
    this.handleLoad();
  },
  methods: {
    handleLoad(){
      if (this.data.id) {
        this.$api.degree.pleaResultsDetail(this.data.id).then(res=>{
          let vals = res.data;
          setTimeout(()=>{
            this.form.setFieldsValue({
              dbcjbjwyrs:vals.dbcjbjwyrs,
              dbcjbjwlrs:vals.dbcjbjwlrs,
              dbcjbjwybrs:vals.dbcjbjwybrs,
              dbcjbjwbhgrs:vals.dbcjbjwbhgrs,
              tjyxlwjgtyrs:vals.tjyxlwjgtyrs,
              tjyxlwjgfdrs:vals.tjyxlwjgfdrs,
              // tjyxlwjgqqrs:vals.tjyxlwjgqqrs,
              xwbjjgtyrs:vals.xwbjjgtyrs,
              xwbjjgfdrs:vals.xwbjjgfdrs,
              xwbjjgqqrs:vals.xwbjjgqqrs,
              bybjjgfdrs:vals.bybjjgfdrs,
              bybjjgqqrs:vals.bybjjgqqrs,
              bybjjgtyrs:vals.bybjjgtyrs,
              dbhjy:vals.dbhjy,
            })
            this.dbhjy = vals.dbhjy
//            this.$refs.wang.editor.txt.html(vals.dbhjy)
          },100)
        })
      }
    },
    handleConclusion(props,vals){
      if (vals) {
          let dbhjyjgnr = '';
          let values = this.form.getFieldsValue(['xwbjjgtyrs','xwbjjgfdrs','xwbjjgqqrs'])
          Object.assign(values,vals)
          for (let n in values) {
           let elem = values[n];
            elem>-1?elem = Number(elem):elem = 0
          }
          let degree = '';
          if(this.data && this.data.xslbm === '432'){
            degree = "博士"
          }
          if(this.data && this.data.xslbm === '431'){
            degree = "硕士"
          }
          let count = values.xwbjjgtyrs+values.xwbjjgfdrs+values.xwbjjgqqrs;
          if (values.xwbjjgtyrs>=count*2/3) {
            dbhjyjgnr = `答辩委员会共有${count}人组成,经无记名投票,${values.xwbjjgtyrs}票同意${values.xwbjjgfdrs}票反对${values.xwbjjgqqrs}票弃权通过学位论文答辩,建议授予${degree}学位`
          }else{
            dbhjyjgnr = `答辩委员会共有${count}人组成,经无记名投票,${values.xwbjjgtyrs}票同意${values.xwbjjgfdrs}票反对${values.xwbjjgqqrs}票弃权通过学位论文答辩,不授予学位`
          }
         this.dbhjyjgnr = dbhjyjgnr;
      }
    },
    handleSave () {
      this.form.validateFields(
        (err, values) => {
          if (!err) {
            let params = Object.assign({},values,{
              dbhjyjgnr:this.dbhjyjgnr,
              dbhjy: this.dbhjy
            })
            this.$emit('success',params);
          }
        },
      );
    },
    handleClose () {
      this.$emit('close')
    },
  }
}

</script>
